package com.mx.zb.md.base.service;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mx.zb.md.base.bo.User;

@RestController
public class HelloService {

	@RequestMapping("/hello")
    public String home(@RequestParam String name) {
		if(StringUtils.isEmpty(name)) {
			name = "empty name";
		}
        return "Hello ,"+name+".";
    }
	
	@RequestMapping("/hello1")
    public User hello(@RequestHeader String name, @RequestHeader Integer age) {
		if(StringUtils.isEmpty(name)) {
			name = "empty name";
		}
		if(age==null)age=0;
        return new User(name, age);
    }
	
	@RequestMapping("/hello2")
    public String hello(@RequestBody User user) {
		if(user!=null) {
			return "Hello "+user.getName()+", age:"+user.getAge();
		}else {
			return "Hello, no user info.";
		}       
    }
	
}
